package com.demo.controller;

import com.demo.beans.PageQuery;
import com.demo.beans.PageResult;
import com.demo.common.JsonData;
import com.demo.model.SysUser;
import com.demo.param.OriginParam;
import com.demo.param.UserParam;
import com.demo.service.OriginService;
import com.demo.service.SysRoleService;
import com.demo.service.SysTreeService;
import com.demo.service.SysUserService;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("/shop/origin")
public class OriginController {

    @Resource
    private OriginService originService;

    @RequestMapping("origin.page")
    public ModelAndView page() {
        return new ModelAndView("/shop/origin");
    }

    @RequestMapping("/list.json")
    @ResponseBody
    public JsonData list() {
        return JsonData.success(originService.getAll());
    }

    @RequestMapping("/page.json")
    @ResponseBody
    public JsonData list(PageQuery pageQuery) {
        return JsonData.success(originService.getPageByAll(pageQuery));
    }

    @RequestMapping("/save.json")
    @ResponseBody
    public JsonData saveUser(OriginParam param) {
        originService.save(param);
        return JsonData.success();
    }

    @RequestMapping("/update.json")
    @ResponseBody
    public JsonData updateUser(OriginParam param) {
        originService.update(param);
        return JsonData.success();
    }

    @RequestMapping("/delete.json")
    @ResponseBody
    public JsonData delete(@RequestParam("originId") int id) {
        originService.delete(id);
        return JsonData.success();
    }


}
